home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "SPMain.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TScratchPad *ScratchPad;
- //---------------------------------------------------------------------------
- __fastcall TScratchPad::TScratchPad(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::FileExitClick(TObject *Sender)
- {
- //
- // All done. Close the form.
- //
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::EditCutClick(TObject *Sender)
- {
- //
- // Call TMemo::CutToClipboard().
- //
- Memo->CutToClipboard();
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::EditCopyClick(TObject *Sender)
- {
- //
- // Call TMemo::CopyToClipboard().
- //
- Memo->CopyToClipboard();
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::EditPasteClick(TObject *Sender)
- {
- //
- // Call TMemo::PasteFromClipboard().
- //
- Memo->PasteFromClipboard();
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::FileNewClick(TObject *Sender)
- {
- //
- // Open a file. First check to see if the current file
- // needs to be saved.
- //
- if (Memo->Modified) {
- //
- // Display a message box.
- //
- int result = Application->MessageBox(
- "The current file has changed. Save changes?",
- "ScratchPad Message", MB_YESNOCANCEL);
- //
- // If Yes was clicked then save the current file.
- //
- if (result == IDYES) FileSaveClick(Sender);
- //
- // If No was clicked then do nothing.
- //
- if (result == IDCANCEL) return;
- }
- //
- // Delete the strings in the memo, if any.
- //
- if (Memo->Lines->Count > 0) Memo->Clear();
- //
- // Set the FileName property of the Save Dialog to a
- // blank string. This lets us know that the file has
- // not yet been saved.
- //
- SaveDialog->FileName = "";
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::FileOpenClick(TObject *Sender)
- {
- //
- // Open a file. First check to see if the current file needs
- // to be saved. Same logic as in FileNewClick() above.
- //
- if (Memo->Modified) {
- int result = Application->MessageBox(
- "The current file has changed. Save changes?",
- "ScratchPad Message", MB_YESNOCANCEL);
- if (result == IDYES) FileSaveClick(0);
- if (result == IDCANCEL) return;
- }
- //
- // Execute the File Open dialog. If OK was pressed then
- // open the file using the LoadFromFile() method. First
- // clear the FileName property.
- //
- OpenDialog->FileName = "";
- if (OpenDialog->Execute())
- {
- if (Memo->Lines->Count > 0) Memo->Clear();
- Memo->Lines->LoadFromFile(OpenDialog->FileName);
- SaveDialog->FileName = OpenDialog->FileName;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::FileSaveClick(TObject *Sender)
- {
- //
- // If a filename has already been provided then there is
- // no need to bring up the File Save dialog. Just save the
- // file using SaveToFile().
- //
- if (SaveDialog->FileName != "")
- {
- Memo->Lines->SaveToFile(SaveDialog->FileName);
- //
- // Set Modified to false since we've just saved.
- //
- Memo->Modified = false;
- }
- //
- // If no filename was set then do a SaveAs().
- //
- else FileSaveAsClick(Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::FileSaveAsClick(TObject *Sender)
- {
- //
- // Display the File Save dialog to save the file.
- // Set Modified to false since we just saved.
- //
- SaveDialog->Title = "Save As";
- if (SaveDialog->Execute())
- {
- Memo->Lines->SaveToFile(SaveDialog->FileName);
- Memo->Modified = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::EditUndoClick(TObject *Sender)
- {
- //
- // TMemo doesn't have an Undo method so we have to send
- // a Windows WM_UNDO message to the memo component.
- //
- SendMessage(Memo->Handle, WM_UNDO, 0, 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::EditSelectAllClick(TObject *Sender)
- {
- //
- // Just call TMemo::SelectAll().
- //
- Memo->SelectAll();
- }
- //---------------------------------------------------------------------------
- void __fastcall TScratchPad::EditWordWrapClick(TObject *Sender)
- {
- //
- // Toggle the TMemo::WordWrap property. Set the Checked
- // property of the menu item to the same value as WordWrap.
- //
- Memo->WordWrap = !Memo->WordWrap;
- EditWordWrap->Checked = Memo->WordWrap;
- //
- // If WordWrap is on then we only need the vertical scroll
- // bar. If it's off, then we need both scroll bars.
- //
- if (Memo->WordWrap) Memo->ScrollBars = ssVertical;
- else Memo->ScrollBars = ssBoth;
- }
- //---------------------------------------------------------------------------
-